#include <iostream>
#include <filesystem>
#include "rapidjson//document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/prettywriter.h"

#include <filesystem>
#include <fstream>
#include <future>
#include <thread>
#include <windows.h>

using namespace std;

int runExternalProgram()
{
    // 监听消息
    int a = 0;
    while (a++ < 10)
    {
        cout << 123 << endl;

        Sleep(100);
    }

    cout << 1323 << endl;

    return 42;
}

void test() {
    
}

int main()
{
    // 启动异步进程
    future<int> future = async(launch::async, runExternalProgram);

    // 在主进程中执行其他任务

    // 等待子线程的完成
    future.wait();

    // 获取异步进程的返回值或消息
    int result = future.get();

    cout << "Received result: " << result << endl;

    cout << 133122 << endl;
    // system("pause");

    return 0;
}